﻿using System.Collections.Generic;
using Jayden.Dll.PathFinding;
using Jayden.Dll.Navigation.Core;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using Jayden.Dll.Navigation.Stib;
using Jayden.Dll.Navigation;
using System.IO;
using Jayden.Dll.Navigation.Tools;

namespace Jayden.Console.Navigation
{
	class Program
	{
		static void Main(string[] args)
		{
			#region STIB
			Station delta = new Station("Delta");
			Station beaulieu = new Station("Beaulieu");
			Station delta2 = new Station("Delta");
			Station fraiteur = new Station("Fraiteur");
			Station cimetiereDIxelles = new Station("Begraalfplaats van Elsene / Cimetière d'Ixelles");
			Station ulb = new Station("ULB");
			Station jeanne = new Station("Johanna / Jeanne");
			Station buyl = new Station("Buyl");
			Station geoBernier = new Station("Géo Bernier");
			Station etangsDIxelles = new Station("Vijvers van Elsene / Etangs d'Ixelles");
			Station flagey = new Station("Flagey");
			Station vanVolsem = new Station("Van Volsem");
			Station fernandCocq = new Station("Fernand Cocq");
			Station quartierStBoniface = new Station("Sint-Bonifaaswijk / Quartier St-Boniface");
			Station porteDeNamur = new Station("Naamsepoort / Porte de Namur");
			Station ducale = new Station("Hertog / Ducale");
			Station royale = new Station("Koning / Royale");
			Station bozar = new Station("Bozar");
			Station gareCentrale = new Station("Centraal Station / Gare Centrale");
			Station arenberg = new Station("Arenberg");
			Station deBrouckere = new Station("De Brouckère");
			Station anspachDeBrouckere = new Station("Anspach-De Brouckère");
			Station assaut = new Station("Storm / Assaut");
			Station matonge = new Station("Matongé");
			Station triomphe = new Station("Triomf / Triomphe");

			TransportationLine stib71 = new TransportationLine(71);
			stib71.StartToEnd.Add(deBrouckere);
			stib71.StartToEnd.Add(anspachDeBrouckere);
			stib71.StartToEnd.Add(assaut);
			stib71.StartToEnd.Add(gareCentrale);
			stib71.StartToEnd.Add(bozar);
			stib71.StartToEnd.Add(royale);
			stib71.StartToEnd.Add(ducale);
			stib71.StartToEnd.Add(porteDeNamur);
			stib71.StartToEnd.Add(matonge);
			stib71.StartToEnd.Add(quartierStBoniface);
			stib71.StartToEnd.Add(fernandCocq);
			stib71.StartToEnd.Add(vanVolsem);
			stib71.StartToEnd.Add(flagey);
			stib71.StartToEnd.Add(etangsDIxelles);
			stib71.StartToEnd.Add(geoBernier);
			stib71.StartToEnd.Add(buyl);
			stib71.StartToEnd.Add(jeanne);
			stib71.StartToEnd.Add(ulb);
			stib71.StartToEnd.Add(cimetiereDIxelles);
			stib71.StartToEnd.Add(fraiteur);
			stib71.StartToEnd.Add(triomphe);
			stib71.StartToEnd.Add(delta);

			stib71.EndToStart.Add(delta);
			stib71.EndToStart.Add(beaulieu);
			stib71.EndToStart.Add(delta2);
			stib71.EndToStart.Add(fraiteur);
			stib71.EndToStart.Add(cimetiereDIxelles);
			stib71.EndToStart.Add(ulb);
			stib71.EndToStart.Add(jeanne);
			stib71.EndToStart.Add(buyl);
			stib71.EndToStart.Add(geoBernier);
			stib71.EndToStart.Add(etangsDIxelles);
			stib71.EndToStart.Add(flagey);
			stib71.EndToStart.Add(vanVolsem);
			stib71.EndToStart.Add(fernandCocq);
			stib71.EndToStart.Add(quartierStBoniface);
			stib71.EndToStart.Add(porteDeNamur);
			stib71.EndToStart.Add(ducale);
			stib71.EndToStart.Add(royale);
			stib71.EndToStart.Add(bozar);
			stib71.EndToStart.Add(gareCentrale);
			stib71.EndToStart.Add(arenberg);
			stib71.EndToStart.Add(deBrouckere);
			#endregion
			#region Hoeilaart
			OneWaySegment desireVandervaerenStraat = new OneWaySegment();
			desireVandervaerenStraat.Coordinates.Add(new Coordinate(50.766482, 4.474244));
			desireVandervaerenStraat.Coordinates.Add(new Coordinate(50.766480, 4.474802));
			desireVandervaerenStraat.Coordinates.Add(new Coordinate(50.766714, 4.475952));

			OneWaySegment emileVandenbroeckStraat = new OneWaySegment();
			emileVandenbroeckStraat.Coordinates.Add(desireVandervaerenStraat.Coordinates[1]);
			emileVandenbroeckStraat.Coordinates.Add(new Coordinate(50.767296, 4.475330));

			OneWaySegment henriCaronStraat = new OneWaySegment();
			henriCaronStraat.Coordinates.Add(new Coordinate(50.767505, 4.474689));
			henriCaronStraat.Coordinates.Add(emileVandenbroeckStraat.Coordinates[1]);
			henriCaronStraat.Coordinates.Add(new Coordinate(50.767232, 4.475437));
			henriCaronStraat.Coordinates.Add(new Coordinate(50.766887, 4.475960));

			Segment waverseSteenweg = new Segment();
			waverseSteenweg.Coordinates.Add(henriCaronStraat.Coordinates[3]);
			waverseSteenweg.Coordinates.Add(desireVandervaerenStraat.Coordinates[2]);
			waverseSteenweg.Coordinates.Add(new Coordinate(50.765827, 4.476320));

			Segment willemEggerickxStraat = new Segment();
			willemEggerickxStraat.Coordinates.Add(henriCaronStraat.Coordinates[0]);
			willemEggerickxStraat.Coordinates.Add(desireVandervaerenStraat.Coordinates[0]);

			Segment paulMalusStraat = new Segment();
			paulMalusStraat.Coordinates.Add(new Coordinate(50.768192, 4.477033));
			paulMalusStraat.Coordinates.Add(new Coordinate(50.767654, 4.477251));
			paulMalusStraat.Coordinates.Add(new Coordinate(50.767240, 4.477409));

			OneWaySegment paulMalusStraat2 = new OneWaySegment();
			paulMalusStraat2.Coordinates.Add(henriCaronStraat.Coordinates[3]);
			paulMalusStraat2.Coordinates.Add(paulMalusStraat.Coordinates[2]);

			OneWaySegment emileVandenbroeckStraat2 = new OneWaySegment();
			emileVandenbroeckStraat2.Coordinates.Add(henriCaronStraat.Coordinates[2]);
			emileVandenbroeckStraat2.Coordinates.Add(paulMalusStraat.Coordinates[1]);

			Segment albertBiesmanLaan = new Segment();
			albertBiesmanLaan.Coordinates.Add(paulMalusStraat.Coordinates[0]);
			albertBiesmanLaan.Coordinates.Add(new Coordinate(50.767579, 4.474297));

			Segment henriCaronStraat2 = new Segment();
			henriCaronStraat2.Coordinates.Add(albertBiesmanLaan.Coordinates[1]);
			henriCaronStraat2.Coordinates.Add(henriCaronStraat.Coordinates[0]);

			Segment jbChalierLaan = new Segment();
			jbChalierLaan.Coordinates.Add(albertBiesmanLaan.Coordinates[1]);
			jbChalierLaan.Coordinates.Add(new Coordinate(50.766860, 4.471889));

			henriCaronStraat2.Coordinates.Insert(0, new Coordinate(50.767825, 4.473029));
			henriCaronStraat2.Coordinates.Insert(0, new Coordinate(50.768288, 4.472803));
			paulMalusStraat.Coordinates.Insert(1, new Coordinate(50.768034, 4.477103));
			albertBiesmanLaan.Coordinates.Insert(0, new Coordinate(50.769450, 4.479616));

			willemEggerickxStraat.Coordinates.Add(new Coordinate(50.765830, 4.473935));
			willemEggerickxStraat.Coordinates.Add(new Coordinate(50.765576, 4.473809));
			willemEggerickxStraat.Coordinates.Add(new Coordinate(50.765484, 4.473758));

			OneWaySegment janVanRuusbroecPark = new OneWaySegment();
			janVanRuusbroecPark.Coordinates.Add(willemEggerickxStraat.Coordinates[willemEggerickxStraat.Coordinates.Count - 3]);
			janVanRuusbroecPark.Coordinates.Add(new Coordinate(50.765759, 4.473241));

			Segment janVanRuusbroecPark2 = new Segment();
			janVanRuusbroecPark2.Coordinates.Add(janVanRuusbroecPark.Coordinates[1]);
			janVanRuusbroecPark2.Coordinates.Add(new Coordinate(50.765706, 4.473246));
			janVanRuusbroecPark2.Coordinates.Add(willemEggerickxStraat.Coordinates[willemEggerickxStraat.Coordinates.Count - 1]);

			OneWaySegment felixSohieStraat = new OneWaySegment();
			felixSohieStraat.Coordinates.Add(henriCaronStraat2.Coordinates[0]);
			felixSohieStraat.Coordinates.Add(new Coordinate(50.768623, 4.473187));
			felixSohieStraat.Coordinates.Add(new Coordinate(50.769130, 4.473353));

			OneWaySegment kerkStraat = new OneWaySegment();
			kerkStraat.Coordinates.Add(henriCaronStraat2.Coordinates[1]);
			kerkStraat.Coordinates.Add(new Coordinate(50.767608, 4.472018));

			Segment marcelFeliceStraat = new Segment();
			marcelFeliceStraat.Coordinates.Add(henriCaronStraat2.Coordinates[0]);
			marcelFeliceStraat.Coordinates.Add(new Coordinate(50.768560, 4.471690));

			OneWaySegment gemeentePlein = new OneWaySegment();
			gemeentePlein.Coordinates.Add(kerkStraat.Coordinates[1]);
			gemeentePlein.Coordinates.Add(marcelFeliceStraat.Coordinates[1]);

			jbChalierLaan.Coordinates.Add(new Coordinate(50.766758, 4.469869));
			jbChalierLaan.Coordinates.Add(new Coordinate(50.766643, 4.466846));
			jbChalierLaan.Coordinates.Add(new Coordinate(50.766601, 4.463373));
			jbChalierLaan.Coordinates.Add(new Coordinate(50.766611, 4.462539));
			jbChalierLaan.Coordinates.Add(new Coordinate(50.766660, 4.460873));
			jbChalierLaan.Coordinates.Add(new Coordinate(50.766662, 4.460524));

			Segment overijseSteenweg = new Segment();
			overijseSteenweg.Coordinates.Add(albertBiesmanLaan.Coordinates[0]);
			overijseSteenweg.Coordinates.Add(new Coordinate(50.769844, 4.482288));

			OneWaySegment overijseSteenweg2 = new OneWaySegment();
			overijseSteenweg2.Coordinates.Add(new Coordinate(50.76950, 4.47635));
			overijseSteenweg2.Coordinates.Add(overijseSteenweg.Coordinates[0]);

			Segment koldamStraat = new Segment();
			koldamStraat.Coordinates.Add(paulMalusStraat.Coordinates[0]);
			koldamStraat.Coordinates.Add(overijseSteenweg2.Coordinates[0]);
			koldamStraat.Coordinates.Add(new Coordinate(50.76958, 4.47634));

			Segment overijseSteenweg3 = new Segment();
			overijseSteenweg3.Coordinates.Add(felixSohieStraat.Coordinates[felixSohieStraat.Coordinates.Count - 1]);
			overijseSteenweg3.Coordinates.Add(koldamStraat.Coordinates[koldamStraat.Coordinates.Count - 1]);

			marcelFeliceStraat.Coordinates.Add(new Coordinate(50.76848013573894, 4.469756484031677));

			Segment groenendaalseSteenweg = new Segment();
			groenendaalseSteenweg.Coordinates.Add(marcelFeliceStraat.Coordinates[marcelFeliceStraat.Coordinates.Count - 1]);
			groenendaalseSteenweg.Coordinates.Add(new Coordinate(50.76835460360542, 4.469552636146545));
			groenendaalseSteenweg.Coordinates.Add(new Coordinate(50.768120502240315, 4.46819543838501));
			groenendaalseSteenweg.Coordinates.Add(new Coordinate(50.76772693788495, 4.463788568973541));
			groenendaalseSteenweg.Coordinates.Add(new Coordinate(50.767565779111585, 4.4634076952934265));
			groenendaalseSteenweg.Coordinates.Add(new Coordinate(50.76736729859619, 4.462582916021347));
			groenendaalseSteenweg.Coordinates.Add(new Coordinate(50.76730113823727, 4.461980760097504));
			groenendaalseSteenweg.Coordinates.Add(new Coordinate(50.76719850467483, 4.461324959993362));
			groenendaalseSteenweg.Coordinates.Add(new Coordinate(50.76695252249301, 4.460451900959015));
			groenendaalseSteenweg.Coordinates.Add(jbChalierLaan.Coordinates[jbChalierLaan.Coordinates.Count - 1]);
			groenendaalseSteenweg.Coordinates.Add(new Coordinate(50.766780, 4.458679));
			groenendaalseSteenweg.Coordinates.Add(new Coordinate(50.76626800664883, 4.450321197509766));
			groenendaalseSteenweg.Coordinates.Add(new Coordinate(50.7668431024172, 4.448942542076111));
			groenendaalseSteenweg.Coordinates.Add(new Coordinate(50.76687872758625, 4.448872804641724));
			groenendaalseSteenweg.Coordinates.Add(new Coordinate(50.76854120530374, 4.444184303283691));
			groenendaalseSteenweg.Coordinates.Add(new Coordinate(50.768658255080084, 4.4439563155174255));
			groenendaalseSteenweg.Coordinates.Add(new Coordinate(50.76877530456359, 4.4437578320503235));

			Segment josephDenayerStraat = new Segment();
			josephDenayerStraat.Coordinates.Add(gemeentePlein.Coordinates[gemeentePlein.Coordinates.Count - 1]);
			josephDenayerStraat.Coordinates.Add(new Coordinate(50.7689949836007, 4.471650123596191));
			josephDenayerStraat.Coordinates.Add(new Coordinate(50.76944706115319, 4.471375197172165));

			waverseSteenweg.Coordinates.Add(new Coordinate(50.76595076790466, 4.476279616355896));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.76583371135419, 4.476327896118164));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.76375378816074, 4.476148188114166));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.76309382583432, 4.474495947360992));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.762854608399486, 4.474053382873535));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.762060601338774, 4.47481244802475));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.761714491480355, 4.475126266479492));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.760937431590186, 4.475863873958588));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.76073552963778, 4.476086497306824));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.75795801688334, 4.4784897565841675));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.756887349438415, 4.479905962944031));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.756301950383126, 4.480834007263184));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.755784417584024, 4.481351673603058));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.755740299769236, 4.481375813484192));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.75537887148981, 4.48167622089386));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.75516167381028, 4.4819095730781555));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.75511755540846, 4.4819846749305725));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.755877743593686, 4.483964145183563));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.75643430211447, 4.485498368740082));
			waverseSteenweg.Coordinates.Add(new Coordinate(50.75660228646528, 4.486370086669922));

			#endregion

			List<PathNode> all = new List<PathNode>();
			//all.Add(new Coordinate(50.824970, 4.366640));
			//all.Add(new Coordinate(50.769091, 4.487067));
			//all.Add(new Coordinate(50.769998, 4.503735));
			//all.Add(new Coordinate(50.770132, 4.503877));
			//all.Add(new Coordinate(50.771998, 4.502048));
			//all.Add(new Coordinate(50.815272, 4.409377));
			all.AddRange(desireVandervaerenStraat.Coordinates);
			all.AddRange(emileVandenbroeckStraat.Coordinates);
			all.AddRange(henriCaronStraat.Coordinates);
			all.AddRange(waverseSteenweg.Coordinates);
			all.AddRange(willemEggerickxStraat.Coordinates);
			all.AddRange(paulMalusStraat.Coordinates);
			all.AddRange(paulMalusStraat2.Coordinates);
			all.AddRange(emileVandenbroeckStraat2.Coordinates);
			all.AddRange(albertBiesmanLaan.Coordinates);
			all.AddRange(henriCaronStraat2.Coordinates);
			all.AddRange(jbChalierLaan.Coordinates);
			all.AddRange(janVanRuusbroecPark.Coordinates);
			all.AddRange(janVanRuusbroecPark2.Coordinates);
			all.AddRange(felixSohieStraat.Coordinates);
			all.AddRange(kerkStraat.Coordinates);
			all.AddRange(marcelFeliceStraat.Coordinates);
			all.AddRange(gemeentePlein.Coordinates);
			all.AddRange(overijseSteenweg.Coordinates);
			all.AddRange(overijseSteenweg2.Coordinates);
			all.AddRange(koldamStraat.Coordinates);
			all.AddRange(overijseSteenweg3.Coordinates);
			all.AddRange(groenendaalseSteenweg.Coordinates);
			all.AddRange(josephDenayerStraat.Coordinates);

			HashSet<PathNode> nodes = new HashSet<PathNode>();
			foreach (PathNode node in all)
				nodes.Add(node);
			List<PathNode> indexes = new List<PathNode>(all);

			desireVandervaerenStraat.Initialize();
			emileVandenbroeckStraat.Initialize();
			henriCaronStraat.Initialize();
			waverseSteenweg.Initialize();
			willemEggerickxStraat.Initialize();
			paulMalusStraat.Initialize();
			paulMalusStraat2.Initialize();
			emileVandenbroeckStraat2.Initialize();
			albertBiesmanLaan.Initialize();
			henriCaronStraat2.Initialize();
			jbChalierLaan.Initialize();
			janVanRuusbroecPark.Initialize();
			janVanRuusbroecPark2.Initialize();
			felixSohieStraat.Initialize();
			kerkStraat.Initialize();
			marcelFeliceStraat.Initialize();
			gemeentePlein.Initialize();
			overijseSteenweg.Initialize();
			overijseSteenweg2.Initialize();
			koldamStraat.Initialize();
			overijseSteenweg3.Initialize();
			groenendaalseSteenweg.Initialize();
			josephDenayerStraat.Initialize();

			Utils.Save("navigation.dat", indexes);
			indexes = Utils.Load("navigation.dat");

			PathNode startNode = waverseSteenweg.Coordinates[waverseSteenweg.Coordinates.Count - 1];
			PathNode endNode = desireVandervaerenStraat.Coordinates[1];

			ShortestPathFinder shortest = new ShortestPathFinder();
			List<PathInformation> shortestPath = shortest.FindPath(startNode, endNode);

			Utils.SaveImage("navigation.png", 1024, indexes, shortestPath);

			System.Console.WriteLine("Press any key to exit.");
			System.Console.ReadKey(true);
		}
	}
}
